package com.martini.admin.controller;

import com.martini.admin.request.register.RegReq;
import com.martini.common.domain.R;
import com.martini.persistent.entity.SysUser;
import com.martini.persistent.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册
 *
 * @author martini at 2021/10/11 9:12
 */
@Slf4j
@RestController
@RequestMapping("/register")
public class RegisterController {

    private final UserService userService;

    public RegisterController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping
    public R register(@RequestBody RegReq regReq) {
        SysUser waitRegSysUser = new SysUser();
        BeanUtils.copyProperties(regReq, waitRegSysUser);
        Integer updated = userService.register(waitRegSysUser);
        if (updated > 0) {
            return R.success();
        } else {
            return R.fail().setMsg("插入失败");
        }
    }

}
